package com.bafa.middle.betwixt;

import com.bafa.jdbc.DBAccess;
import com.bafa.objects.player.Player;

import java.io.StringReader;
import java.io.StringWriter;
    import java.io.StringWriter;

import java.sql.ResultSet;

import org.apache.commons.betwixt.io.BeanReader;
import org.apache.commons.betwixt.io.BeanWriter;
public class Write {
  



        /** 
         * Create an example bean and then convert it to xml.
         */
        public static final void main(String [] args) throws Exception {
            
        //   Player player = new Player("Reda","Hmeid",13,52,1);
          DBAccess db = new DBAccess();
           //db.storePlayer(player);
           
          ResultSet players = db.retrievePlayer(1);
          
            while (players.next()) {
                try {
                    String playerBlob = new String(players.getBytes("player"));
                    System.out.println(playerBlob);
                    // First construct the xml which will be read in
                           // For this example, read in from a hard coded string
                           StringReader xmlReader = new StringReader(playerBlob);
                           
                           // Now convert this to a bean using betwixt
                           // Create BeanReader
                           BeanReader beanReader  = new BeanReader();
                           
                           // Configure the reader
                           // If you're round-tripping, make sure that the configurations are compatible!
                           beanReader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
                           beanReader.getBindingConfiguration().setMapIDs(false);
                           
                           // Register beans so that betwixt knows what the xml is to be converted to
                           // Since the element mapped to a PersonBean isn't called the same 
                           // as Betwixt would have guessed, need to register the path as well
                           beanReader.registerBeanClass("player", com.bafa.objects.player.Player.class);
                           
                           // Now we parse the xml
                           Player person = (Player) beanReader.parse(xmlReader);
                           
                           // send bean to system out
                           System.out.println(person);
                }catch(Exception e){}
            }
        }
    
}
